package com.yuexunit.operationman.nbsy.module.nurse.ui;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.bumptech.glide.Glide;

import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.base.ExitApplication;
import com.yuexunit.operationman.nbsy.base.SubmitBean;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.Bean.DrugBean;
import com.yuexunit.operationman.nbsy.module.InterventionalOperation.adapter.OtherListAdapter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.bean.SignBean;
import com.yuexunit.operationman.nbsy.module.SafeOperation.model.impl.SafeOperationSignModel;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.ISafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.presenter.impl.SafeOperationSignPresenter;
import com.yuexunit.operationman.nbsy.module.SafeOperation.ui.view.ISafeOperationSignView;
import com.yuexunit.operationman.nbsy.module.nurse.Bean.NurseBean;
import com.yuexunit.operationman.nbsy.module.nurse.model.impl.NurseModel;
import com.yuexunit.operationman.nbsy.module.nurse.presenter.INursePresenter;
import com.yuexunit.operationman.nbsy.module.nurse.presenter.impl.NursePresenter;
import com.yuexunit.operationman.nbsy.module.nurse.ui.view.INurseView;
import com.yuexunit.operationman.nbsy.module.plant.ui.Act_Flax_Meter;
import com.yuexunit.operationman.nbsy.widget.ActionSheetDialog;
import com.yuexunit.operationman.nbsy.widget.ClickDialog;
import com.yuexunit.operationman.nbsy.widget.CustomDatePicker;
import com.yuexunit.operationman.nbsy.widget.FixedSwipeListView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;
import com.yuexunit.operationman.nbsy.widget.LoginDialog;

import org.kymjs.kjframe.ui.ViewInject;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/7/7 0007.
 */

public class Act_Ops_Ing extends BaseKJActivity implements ISafeOperationSignView, INurseView {
    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.supine_position)
    CheckBox supinePosition;
    @Bind(R.id.neck_supine)
    CheckBox neckSupine;
    @Bind(R.id.prone_position)
    CheckBox pronePosition;
    @Bind(R.id.lithotomy_position)
    CheckBox lithotomyPosition;
    @Bind(R.id.fold_position)
    CheckBox foldPosition;
    @Bind(R.id.lateral_position_left)
    CheckBox lateralPositionLeft;
    @Bind(R.id.lateral_position_right)
    CheckBox lateralPositionRight;
    @Bind(R.id.position_other)
    CheckBox positionOther;
    @Bind(R.id.angle_30)
    CheckBox angle30;
    @Bind(R.id.angle_45)
    CheckBox angle45;
    @Bind(R.id.angle_90)
    CheckBox angle90;
    @Bind(R.id.iv_lateral_angle)
    LinearLayout ivLateralAngle;
    @Bind(R.id.iv_skin_other)
    LinearLayout ivSkinOther;
    @Bind(R.id.position_other_txt)
    EditText positionOtherTxt;
    @Bind(R.id.tourniquet_has)
    CheckBox tourniquetHas;
    @Bind(R.id.tourniquet_none)
    CheckBox tourniquetNone;
    @Bind(R.id.iv_tourniquet_has)
    LinearLayout ivTourniquetHas;
    @Bind(R.id.tourniquet_stress_txt)
    EditText tourniquetStressTxt;
    @Bind(R.id.start_time_1)
    TextView startTime1;
    @Bind(R.id.end_time_1)
    TextView endTime1;
    @Bind(R.id.start_time_2)
    TextView startTime2;
    @Bind(R.id.end_time_2)
    TextView endTime2;
    @Bind(R.id.ops_ing_01_01)
    CheckBox opsIng0101;
    @Bind(R.id.ops_ing_01_02)
    CheckBox opsIng0102;
    @Bind(R.id.insert_none)
    CheckBox insertNone;
    @Bind(R.id.bed_risk_mentality)
    CheckBox bedRiskMentality;
    @Bind(R.id.frozen_section_none)
    CheckBox frozenSectionNone;
    @Bind(R.id.frozen_section_has)
    CheckBox frozenSectionHas;
    @Bind(R.id.iv_frozen_section)
    LinearLayout ivFrozenSection;
    @Bind(R.id.frozen_name)
    EditText frozenName;
    @Bind(R.id.frozen_count)
    EditText frozenCount;
    @Bind(R.id.conventional_slice_none)
    CheckBox conventionalSliceNone;
    @Bind(R.id.conventional_slice_has)
    CheckBox conventionalSliceHas;
    @Bind(R.id.iv_conventional_slice)
    LinearLayout ivConventionalSlice;
    @Bind(R.id.conventional_name)
    EditText conventionalName;
    @Bind(R.id.conventional_count)
    EditText conventionalCount;
    @Bind(R.id.specimen_none)
    CheckBox specimenNone;
    @Bind(R.id.specimen_other)
    CheckBox specimenOther;
    @Bind(R.id.iv_specimen_other)
    LinearLayout ivSpecimenOther;
    @Bind(R.id.specimen_other_txt)
    EditText specimenOtherTxt;
    @Bind(R.id.specimen_other_count)
    EditText specimenOtherCount;
    @Bind(R.id.drain_none)
    CheckBox drainNone;
    @Bind(R.id.drain_has)
    CheckBox drainHas;
    @Bind(R.id.iv_drain)
    LinearLayout ivDrain;
    @Bind(R.id.drain_count)
    EditText drainCount;
    @Bind(R.id.drain_position)
    EditText drainPosition;
    @Bind(R.id.general_anesthesia)
    CheckBox generalAnesthesia;
    @Bind(R.id.intraspinal_anesthesia)
    CheckBox intraspinalAnesthesia;
    @Bind(R.id.nerve_block_anesthesia)
    CheckBox nerveBlockAnesthesia;
    @Bind(R.id.local_anesthesia)
    CheckBox localAnesthesia;
    @Bind(R.id.iv_local_anesthesia)
    LinearLayout ivLocalAnesthesia;
    @Bind(R.id.narcotic)
    EditText narcotic;
    @Bind(R.id.dosage)
    EditText dosage;
    @Bind(R.id.anesthesia_people)
    EditText anesthesiaPeople;
    @Bind(R.id.anesthesia_start)
    TextView anesthesiaStart;
    @Bind(R.id.operation_start)
    TextView operationStart;
    @Bind(R.id.operation_end)
    TextView operationEnd;
    @Bind(R.id.surgeon)
    EditText surgeon;
    @Bind(R.id.infusion_medication)
    EditText infusionMedication;
    @Bind(R.id.tour)
    EditText tour;
    @Bind(R.id.before_condition)
    EditText beforeCondition;
    @Bind(R.id.after_condition)
    EditText afterCondition;
    @Bind(R.id.after_advice)
    EditText afterAdvice;
    @Bind(R.id.anesthesia_end)
    TextView anesthesiaEnd;
    //    @Bind(R.id.mentality_name_tv)
//    EditText mentalityNameTv;
    @Bind(R.id.mentality_ll)
    LinearLayout mentalityLl;
    @Bind(R.id.analgesia_listview)
    FixedSwipeListView analgesiaListview;

    //签名
    @Bind(R.id.img_ra_sign_02)
    ImageView imgRaSign02;
    @Bind(R.id.btn_ra_sign_02)
    TextView btnRaSign02;
    @Bind(R.id.tv_ra_sign_02_time)
    TextView tvRaSign02Time;
    @Bind(R.id.tv_ra_sign_02_name)
    TextView tvRaSign02Name;

    LoadingDialog loadingDialog;
    INursePresenter presenter;
    ArrayList<DrugBean> OtherDrugBeans = new ArrayList<>();
    OtherListAdapter otherListAdapter;

    ISafeOperationSignPresenter presenter_sign;
    LoginDialog loginDialog;

    ClickDialog dialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_ops_ing);
        ButterKnife.bind(this);
        ExitApplication.getInstance().addActivity(this);
    }

    @Override
    public void initData() {
        super.initData();
        loginDialog = new LoginDialog(aty);
        loadingDialog = new LoadingDialog(this);
        presenter = new NursePresenter(this, new NurseModel());
        presenter_sign = new SafeOperationSignPresenter(this, new SafeOperationSignModel());
        setTitle();
        setContent();

        analgesiaListview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(aty, Act_Nursing_Implant.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("drug", OtherDrugBeans.get(i));
                bundle.putInt("type", 2);
                bundle.putInt("position", i);
                intent.putExtras(bundle);
                aty.startActivityForResult(intent, 1);
            }
        });
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.NURSEBEAN.getObject().getNursing().getPatientName());
        if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.NURSEBEAN.getObject().getNursing().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.NURSEBEAN.getObject().getNursing().getInHospitalNo());
        tvPatientDisease.setText(AppConfig.NURSEBEAN.getObject().getNursing().getOperationName());
    }

    private void setContent() {
        for (NurseBean.ObjectEntity.NursingItemListEntity p : AppConfig.NURSEBEAN.getObject().getNursingItemList()) {
            switch (p.getItemCode()) {
                case "SP_TiWei":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            supinePosition.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            neckSupine.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            pronePosition.setChecked(true);
                        }
                        if (skin[7].equals("1")) {
                            lithotomyPosition.setChecked(true);
                        }
                        if (skin[8].equals("1")) {
                            foldPosition.setChecked(true);
                        }
                        if (skin[5].equals("1")) {
                            lateralPositionLeft.setChecked(true);
                            ivLateralAngle.setVisibility(View.VISIBLE);
                            if (skin[4].equals("30")) {
                                angle30.setChecked(true);
                            }
                            if (skin[4].equals("45")) {
                                angle45.setChecked(true);
                            }
                            if (skin[4].equals("90")) {
                                angle90.setChecked(true);
                            }
                        }
                        if (skin[6].equals("1")) {
                            lateralPositionRight.setChecked(true);
                            ivLateralAngle.setVisibility(View.VISIBLE);
                            if (skin[4].equals("30")) {
                                angle30.setChecked(true);
                            }
                            if (skin[4].equals("45")) {
                                angle45.setChecked(true);
                            }
                            if (skin[4].equals("90")) {
                                angle90.setChecked(true);
                            }
                        }
                    }

                    if (p.getItemOther().length() > 0) {
                        positionOther.setChecked(true);
                        positionOtherTxt.setText(p.getItemOther());
                        ivSkinOther.setVisibility(View.VISIBLE);
                    }
                    break;
                case "SP_ZhiXueDai":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            tourniquetNone.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            tourniquetHas.setChecked(true);
                            ivTourniquetHas.setVisibility(View.VISIBLE);
                            tourniquetStressTxt.setText(skin[2]);
                            if (skin[3].length() > 0) {
                                String[] time = skin[3].split("~", -1);
                                startTime1.setText(time[0]);
                                endTime1.setText(time[1]);
                            }
                            if (skin[4].length() > 0) {
                                String[] time = skin[4].split("~", -1);
                                startTime2.setText(time[0]);
                                endTime2.setText(time[1]);
                            }
                        }
                    }
                    break;
                case "SP_ZhiRuWu":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            insertNone.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            bedRiskMentality.setChecked(true);
                            mentalityLl.setVisibility(View.VISIBLE);
//                        mentalityNameTv.setText(p.getItemOther());
                            if (p.getItemOther().length() > 0) {
                                String[] medicine = p.getItemOther().split(";", -1);

                                for (int i = 0; i < medicine.length; i++) {
                                    DrugBean drugBean = new DrugBean();
                                    drugBean.setName(medicine[i]);
                                    OtherDrugBeans.add(drugBean);
                                }

                                otherListAdapter = new OtherListAdapter(analgesiaListview, OtherDrugBeans, R.layout.item_other_list);
                                analgesiaListview.setAdapter(otherListAdapter);
                            }
                        }
                    }
                    break;
                case "SP_ZhiRuWuSign":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            opsIng0101.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            opsIng0102.setChecked(true);
                        }
                    }
                    break;
                case "SP_ShouShuBiaoBen_BingDongQiePian":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[2].equals("1")) {
                            frozenSectionNone.setChecked(true);
                        }
                        if (skin[2].equals("0")) {
                            frozenSectionHas.setChecked(true);
                            ivFrozenSection.setVisibility(View.VISIBLE);
                            frozenName.setText(skin[0]);
                            frozenCount.setText(skin[1]);
                        }
                    }
                    break;
                case "SP_ShouShuBiaoBen_ChangGuiQiePian":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[2].equals("1")) {
                            conventionalSliceNone.setChecked(true);
                        }
                        if (skin[2].equals("0")) {
                            conventionalSliceHas.setChecked(true);
                            ivConventionalSlice.setVisibility(View.VISIBLE);
                            conventionalName.setText(skin[0]);
                            conventionalCount.setText(skin[1]);
                        }
                    }
                    break;
                case "SP_ShouShuBiaoBen_other":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin.length == 3) {
                            if (skin[2].equals("0")) {
                                specimenNone.setChecked(true);
                            }
                            if (skin[2].equals("1")) {
                                specimenOther.setChecked(true);
                                ivSpecimenOther.setVisibility(View.VISIBLE);
                                specimenOtherTxt.setText(skin[0]);
                                specimenOtherCount.setText(skin[1]);
                            }
                        }
                    }
                    break;
                case "SP_YinLiuWu":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            drainNone.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            drainHas.setChecked(true);
                            ivDrain.setVisibility(View.VISIBLE);
                            drainCount.setText(skin[2]);
                            drainPosition.setText(skin[3]);
                        }
                    }
                    break;
                case "SP_MaZuiZhongLei":
                    if (p.getItemValue().length() > 0) {
                        String[] skin = p.getItemValue().split(";", -1);
                        if (skin[0].equals("1")) {
                            generalAnesthesia.setChecked(true);
                        }
                        if (skin[1].equals("1")) {
                            intraspinalAnesthesia.setChecked(true);
                        }
                        if (skin[2].equals("1")) {
                            nerveBlockAnesthesia.setChecked(true);
                        }
                        if (skin[3].equals("1")) {
                            localAnesthesia.setChecked(true);
//                            ivLocalAnesthesia.setVisibility(View.VISIBLE);
//                            if (AppConfig.NURSEBEAN.getObject().getAnaesthesia().getDrugDesc().length() > 0) {
//                                String[] drugDesc = AppConfig.NURSEBEAN.getObject().getAnaesthesia().getDrugDesc().split(";", -1);
//                                narcotic.setText(drugDesc[0]);
//                                dosage.setText(drugDesc[1]);
//                            }
//                            anesthesiaPeople.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getAnesthetist());
//                            anesthesiaStart.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getAnesthesiaStartTime());
//                            anesthesiaEnd.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getAnesthesiaEndTime());
//                            tour.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getCircuitDoctor());
//                            beforeCondition.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getBeforeOperationDesc());
//                            operationStart.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getOperationStartTime());
//                            operationEnd.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getOperationEndTime());
//                            afterCondition.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getAfterOperationDesc());
//                            surgeon.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getOperationDoctor());
//                            afterAdvice.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getDoctorAdvice());
//                            infusionMedication.setText(AppConfig.NURSEBEAN.getObject().getAnaesthesia().getDrugDrain());
                        }
                    }
                    break;
                case "SP_Over_Sign":
                    if (p.getItemValue().length() > 0) {
                        imgRaSign02.setVisibility(View.VISIBLE);
                        btnRaSign02.setVisibility(View.GONE);
                        tvRaSign02Time.setVisibility(View.VISIBLE);
                        tvRaSign02Name.setVisibility(View.VISIBLE);
                        Glide.with(aty)
                                .load(p.getItemValue())
                                .placeholder(R.color.white)
                                .error(R.color.white)
                                .into(imgRaSign02);
                        tvRaSign02Time.setText("签名时间:" + p.getItemOther());
                        tvRaSign02Name.setText(p.getItemName());
                    }
                    break;
            }
        }
    }


    @OnClick({R.id.titlebar_docadvice_img_back, R.id.supine_position, R.id.neck_supine, R.id.prone_position, R.id.lithotomy_position,
            R.id.fold_position, R.id.lateral_position_left, R.id.lateral_position_right, R.id.position_other,
            R.id.angle_30, R.id.angle_45, R.id.angle_90, R.id.tourniquet_has, R.id.tourniquet_none, R.id.start_time_1, R.id.end_time_1,
            R.id.start_time_2, R.id.end_time_2, R.id.insert_none, R.id.bed_risk_mentality,
            R.id.frozen_section_none, R.id.frozen_section_has, R.id.conventional_slice_none, R.id.conventional_slice_has,
            R.id.specimen_none, R.id.specimen_other, R.id.drain_none, R.id.drain_has, R.id.general_anesthesia,
            R.id.intraspinal_anesthesia, R.id.nerve_block_anesthesia, R.id.local_anesthesia, R.id.anesthesia_start,
            R.id.operation_start, R.id.operation_end, R.id.flax_meter, R.id.sure,
            R.id.ops_ing_01_01, R.id.ops_ing_01_02, R.id.anesthesia_end, R.id.bt_add_analgesia, R.id.btn_ra_sign_02})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.supine_position:
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.neck_supine:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.prone_position:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.lithotomy_position:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.fold_position:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.lateral_position_left:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    ivLateralAngle.setVisibility(View.VISIBLE);
                } else {
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.lateral_position_right:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                }
                if (lateralPositionRight.isChecked()) {
                    ivLateralAngle.setVisibility(View.VISIBLE);
                } else {
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    positionOther.setChecked(false);
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.position_other:
                if (supinePosition.isChecked()) {
                    supinePosition.setChecked(false);
                }
                if (neckSupine.isChecked()) {
                    neckSupine.setChecked(false);
                }
                if (pronePosition.isChecked()) {
                    pronePosition.setChecked(false);
                }
                if (lithotomyPosition.isChecked()) {
                    lithotomyPosition.setChecked(false);
                }
                if (foldPosition.isChecked()) {
                    foldPosition.setChecked(false);
                }
                if (lateralPositionLeft.isChecked()) {
                    lateralPositionLeft.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (lateralPositionRight.isChecked()) {
                    lateralPositionRight.setChecked(false);
                    ivLateralAngle.setVisibility(View.GONE);
                }
                if (positionOther.isChecked()) {
                    ivSkinOther.setVisibility(View.VISIBLE);
                } else {
                    ivSkinOther.setVisibility(View.GONE);
                }
                break;
            case R.id.angle_30:
                if (angle45.isChecked()) {
                    angle45.setChecked(false);
                }
                if (angle90.isChecked()) {
                    angle90.setChecked(false);
                }
                break;
            case R.id.angle_45:
                if (angle30.isChecked()) {
                    angle30.setChecked(false);
                }
                if (angle90.isChecked()) {
                    angle90.setChecked(false);
                }
                break;
            case R.id.angle_90:
                if (angle30.isChecked()) {
                    angle30.setChecked(false);
                }
                if (angle45.isChecked()) {
                    angle45.setChecked(false);
                }
                break;
            case R.id.tourniquet_has:
                if (tourniquetNone.isChecked()) {
                    tourniquetNone.setChecked(false);
                }
                if (tourniquetHas.isChecked()) {
                    ivTourniquetHas.setVisibility(View.VISIBLE);
                } else {
                    ivTourniquetHas.setVisibility(View.GONE);
                }
                break;
            case R.id.tourniquet_none:
                if (tourniquetHas.isChecked()) {
                    tourniquetHas.setChecked(false);
                    ivTourniquetHas.setVisibility(View.GONE);
                }
                break;
            case R.id.start_time_1:
                initDatePicker(startTime1);
                break;
            case R.id.end_time_1:
                initDatePicker(endTime1);
                break;
            case R.id.start_time_2:
                initDatePicker(startTime2);
                break;
            case R.id.end_time_2:
                initDatePicker(endTime2);
                break;
            case R.id.insert_none:
                if (bedRiskMentality.isChecked()) {
                    bedRiskMentality.setChecked(false);
                }
                mentalityLl.setVisibility(View.GONE);
                break;
            case R.id.bed_risk_mentality:
                if (insertNone.isChecked()) {
                    insertNone.setChecked(false);
                    mentalityLl.setVisibility(View.GONE);
                }
                mentalityLl.setVisibility(View.VISIBLE);
                break;
            case R.id.frozen_section_none:
                if (frozenSectionHas.isChecked()) {
                    frozenSectionHas.setChecked(false);
                    ivFrozenSection.setVisibility(View.GONE);
                }
                break;
            case R.id.frozen_section_has:
                if (frozenSectionNone.isChecked()) {
                    frozenSectionNone.setChecked(false);
                }
                if (frozenSectionHas.isChecked()) {
                    ivFrozenSection.setVisibility(View.VISIBLE);
                } else {
                    ivFrozenSection.setVisibility(View.GONE);
                }
                break;
            case R.id.conventional_slice_none:
                if (conventionalSliceHas.isChecked()) {
                    conventionalSliceHas.setChecked(false);
                    ivConventionalSlice.setVisibility(View.GONE);
                }
                break;
            case R.id.conventional_slice_has:
                if (conventionalSliceNone.isChecked()) {
                    conventionalSliceNone.setChecked(false);
                }
                if (conventionalSliceHas.isChecked()) {
                    ivConventionalSlice.setVisibility(View.VISIBLE);
                } else {
                    ivConventionalSlice.setVisibility(View.GONE);
                }
                break;
            case R.id.specimen_none:
                if (specimenOther.isChecked()) {
                    specimenOther.setChecked(false);
                    ivSpecimenOther.setVisibility(View.GONE);
                }
                break;
            case R.id.specimen_other:
                if (specimenNone.isChecked()) {
                    specimenNone.setChecked(false);
                }
                if (specimenOther.isChecked()) {
                    ivSpecimenOther.setVisibility(View.VISIBLE);
                } else {
                    ivSpecimenOther.setVisibility(View.GONE);
                }
                break;
            case R.id.drain_none:
                if (drainHas.isChecked()) {
                    drainHas.setChecked(false);
                    ivDrain.setVisibility(View.GONE);
                }
                break;
            case R.id.drain_has:
                if (drainNone.isChecked()) {
                    drainNone.setChecked(false);
                }
                if (drainHas.isChecked()) {
                    ivDrain.setVisibility(View.VISIBLE);
                } else {
                    ivDrain.setVisibility(View.GONE);
                }
                break;
            case R.id.general_anesthesia:
                if (intraspinalAnesthesia.isChecked()) {
                    intraspinalAnesthesia.setChecked(false);
                }
                if (nerveBlockAnesthesia.isChecked()) {
                    nerveBlockAnesthesia.setChecked(false);
                }
                if (localAnesthesia.isChecked()) {
                    localAnesthesia.setChecked(false);
                    ivLocalAnesthesia.setVisibility(View.GONE);
                }
                break;
            case R.id.intraspinal_anesthesia:
                if (generalAnesthesia.isChecked()) {
                    generalAnesthesia.setChecked(false);
                }
                if (nerveBlockAnesthesia.isChecked()) {
                    nerveBlockAnesthesia.setChecked(false);
                }
                if (localAnesthesia.isChecked()) {
                    localAnesthesia.setChecked(false);
                    ivLocalAnesthesia.setVisibility(View.GONE);
                }
                break;
            case R.id.nerve_block_anesthesia:
                if (intraspinalAnesthesia.isChecked()) {
                    intraspinalAnesthesia.setChecked(false);
                }
                if (generalAnesthesia.isChecked()) {
                    generalAnesthesia.setChecked(false);
                }
                if (localAnesthesia.isChecked()) {
                    localAnesthesia.setChecked(false);
                    ivLocalAnesthesia.setVisibility(View.GONE);
                }
                break;
            case R.id.local_anesthesia:
                if (generalAnesthesia.isChecked()) {
                    generalAnesthesia.setChecked(false);
                }
                if (intraspinalAnesthesia.isChecked()) {
                    intraspinalAnesthesia.setChecked(false);
                }
                if (nerveBlockAnesthesia.isChecked()) {
                    nerveBlockAnesthesia.setChecked(false);
                }
                if (localAnesthesia.isChecked()) {
//                    ivLocalAnesthesia.setVisibility(View.VISIBLE);
//                } else {
//                    ivLocalAnesthesia.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.anesthesia_start:
                initDatePicker(anesthesiaStart);
                break;
            case R.id.operation_start:
                initDatePicker(operationStart);
                break;
            case R.id.operation_end:
                initDatePicker(operationEnd);
                break;
            case R.id.flax_meter:
                startActivity(new Intent(aty, Act_Flax_Meter.class));
                break;
            case R.id.sure:
                boolean sign01=false;
                for (int i = 0; i < AppConfig.NURSEBEAN.getObject().getNursingItemList().size(); i++) {
                    if (AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).getItemCode().equals("SP_Over_Sign")) {
                        if(AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).getItemName().length()>0)
                        {
                            sign01=true;
                        }
                    }
                }

                if(sign01) {
                    insertContent();
                }
                else {
                    dialog = new ClickDialog(aty).builder().setTxt("存在未签名,是否提交？");
                    dialog.isCancleBack(true);
                    dialog.setCallBack(new ClickDialog.ICallBack() {
                        @Override
                        public void callback(Bundle bundle) {
                            if(bundle.getInt("data") == 0){
                                insertContent();
                            } else if(bundle.getInt("data") == 1){
                                dialog.dismiss();
                            }

                        }
                    });
                    dialog.show();
                }
                break;
            case R.id.ops_ing_01_01:
                if (opsIng0102.isChecked()) {
                    opsIng0102.setChecked(false);
                }
                break;
            case R.id.ops_ing_01_02:
                if (opsIng0101.isChecked()) {
                    opsIng0101.setChecked(false);
                }
                break;
            case R.id.anesthesia_end:
                initDatePicker(anesthesiaEnd);
                break;
            case R.id.bt_add_analgesia:
                Intent intent1 = new Intent(this, Act_Nursing_Implant.class);
                Bundle bundle1 = new Bundle();
                bundle1.putInt("type", 1);
                intent1.putExtras(bundle1);
                aty.startActivityForResult(intent1, 1);
                break;
            case R.id.btn_ra_sign_02:
                showTypeDialog();
                break;
        }
    }

    private void showTypeDialog() {
        ActionSheetDialog actionSheetDialog;
        actionSheetDialog = new ActionSheetDialog(this).builder()
                .setCancelable(true)
                .setCanceledOnTouchOutside(true);
        actionSheetDialog.addSheetItem("HIS签名", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {
                        loginDialog.builder();
                        loginDialog.show();
                        loginDialog.setCallBack(new LoginDialog.ICallBack() {
                            @Override
                            public void callback(Bundle bundle) {
                                Map<String, String> params = new HashMap<>();
                                params.put("jobNum", bundle.getString("person_num"));
                                params.put("loginPwd", bundle.getString("person_psw"));
                                presenter_sign.getSignInfo(params);
                            }
                        });
                    }
                });
        actionSheetDialog.addSheetItem("虹膜签名(暂不可用)", ActionSheetDialog.SheetItemColor.Blue,
                new ActionSheetDialog.OnSheetItemClickListener() {
                    @Override
                    public void onClick(int which) {

                    }
                });
        actionSheetDialog.show();
    }

    @Override
    public void getSignInfo(SignBean signBean) {
        loginDialog.dismiss();
        if (signBean.getCode() == 200) {
            if (signBean.getObject().getDoctorType().equals("H")) {
                SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
                Date curDate = new Date(System.currentTimeMillis());//获取当前时间
                String str = formatter.format(curDate);
                imgRaSign02.setVisibility(View.VISIBLE);
                Glide.with(this)
                        .load(signBean.getObject().getSignPicture())
                        .placeholder(R.color.white)
                        .error(R.color.white)
                        .into(imgRaSign02);
                btnRaSign02.setVisibility(View.GONE);
                tvRaSign02Time.setVisibility(View.VISIBLE);
                tvRaSign02Time.setText("签名时间:" + str);
                tvRaSign02Name.setVisibility(View.VISIBLE);
                tvRaSign02Name.setText(signBean.getObject().getDoctorName());

                for (int i = 0; i < AppConfig.NURSEBEAN.getObject().getNursingItemList().size(); i++) {
                    if (AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).getItemCode().equals("SP_Over_Sign")) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(signBean.getObject().getSignPicture());
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemName(signBean.getObject().getDoctorName());
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemOther(str);
                    }
                }
            } else {
                ViewInject.toast("请使用护士账号进行签名");
            }

        } else {
            ViewInject.toast(signBean.getDesc());
        }
    }

    private void insertContent() {
        for (int i = 0; i < AppConfig.NURSEBEAN.getObject().getNursingItemList().size(); i++) {
            String value = "";
            switch (AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).getItemCode()) {
                case "SP_TiWei":
                    if (supinePosition.isChecked()) {
                        value += "1;;;;;;;;";
                    }
                    if (neckSupine.isChecked()) {
                        value += ";1;;;;;;;";
                    }
                    if (pronePosition.isChecked()) {
                        value += ";;1;;;;;;";
                    }
                    if (lithotomyPosition.isChecked()) {
                        value += ";;;;;;;1;";
                    }
                    if (foldPosition.isChecked()) {
                        value += ";;;;;;;;1";
                    }
                    if (lateralPositionLeft.isChecked()) {
                        if (angle30.isChecked()) {
                            value += ";;;1;30;1;;;";
                        } else if (angle45.isChecked()) {
                            value += ";;;1;45;1;;;";
                        } else if (angle45.isChecked()) {
                            value += ";;;1;90;1;;;";
                        } else {
                            value += ";;;1;;1;;;";
                        }
                    }
                    if (lateralPositionRight.isChecked()) {
                        if (angle30.isChecked()) {
                            value += ";;;1;30;;1;;";
                        } else if (angle45.isChecked()) {
                            value += ";;;1;45;;1;;";
                        } else if (angle45.isChecked()) {
                            value += ";;;1;90;;1;;";
                        } else {
                            value += ";;;1;;;1;;";
                        }
                    }
                    AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(value);
                    if (positionOther.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemOther(positionOtherTxt.getText().toString());
                    }
                    break;
                case "SP_ZhiXueDai":
                    if (tourniquetHas.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";1" + ";" + tourniquetStressTxt.getText().toString()
                                + ";" + startTime1.getText().toString() + "~" + endTime1.getText().toString()
                                + ";" + startTime2.getText().toString() + "~" + endTime2.getText().toString());
                    }
                    if (tourniquetNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue("1;;;;");
                    }
                    break;
                case "SP_ZhiRuWu":
                    if (insertNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue("1;");
                    }
                    if (bedRiskMentality.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";1");
                        if (OtherDrugBeans.size() > 0) {
                            String medicine = "";
                            for (int j = 0; j < OtherDrugBeans.size(); j++) {
                                if (medicine.length() > 0) {
                                    medicine += ";" + OtherDrugBeans.get(j).getName();
                                } else {
                                    medicine += OtherDrugBeans.get(j).getName();
                                }
                            }
                            AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemOther(medicine);
                        } else if (OtherDrugBeans.size() == 0) {
                            AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemOther("");
                        }
                    }
                    break;
                case "SP_ZhiRuWuSign":
                    if (opsIng0101.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue("1;");
                    } else if (opsIng0102.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";1");
                    } else {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";");
                    }
                    break;
                case "SP_ShouShuBiaoBen_BingDongQiePian":
                    if (frozenSectionNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";;1");
                    }
                    if (frozenSectionHas.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(frozenName.getText().toString() +
                                ";" + frozenCount.getText().toString() + ";0");
                    }
                    break;
                case "SP_ShouShuBiaoBen_ChangGuiQiePian":
                    if (conventionalSliceNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";;1");
                    }
                    if (conventionalSliceHas.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(conventionalName.getText().toString() +
                                ";" + conventionalCount.getText().toString() + ";0");
                    }
                    break;
                case "SP_ShouShuBiaoBen_other":
                    if (specimenNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";;0");
                    }
                    if (specimenOther.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(specimenOtherTxt.getText().toString() +
                                ";" + specimenOtherCount.getText().toString() + ";1");
                    }
                    break;
                case "SP_YinLiuWu":
                    if (drainNone.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue("1;;;");
                    }
                    if (drainHas.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";1;" + drainCount.getText().toString() +
                                ";" + drainPosition.getText().toString());
                    }
                    break;
                case "SP_MaZuiZhongLei":
                    if (generalAnesthesia.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue("1;;;");
                    }
                    if (intraspinalAnesthesia.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";1;;");
                    }
                    if (nerveBlockAnesthesia.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";;1;");
                    }
                    if (localAnesthesia.isChecked()) {
                        AppConfig.NURSEBEAN.getObject().getNursingItemList().get(i).setItemValue(";;;1");
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setDrugDesc(narcotic.getText().toString() + ";" + dosage.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setAnesthetist(anesthesiaPeople.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setAnesthesiaStartTime(anesthesiaStart.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setAnesthesiaEndTime(anesthesiaEnd.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setBeforeOperationDesc(beforeCondition.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setCircuitDoctor(tour.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setOperationStartTime(operationStart.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setOperationEndTime(operationEnd.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setAfterOperationDesc(afterCondition.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setDoctorAdvice(afterAdvice.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setOperationDoctor(surgeon.getText().toString());
//                        AppConfig.NURSEBEAN.getObject().getAnaesthesia().setDrugDrain(infusionMedication.getText().toString());
                    }
                    break;
            }
        }

        if (AppConfig.NURSEBEAN.getObject().getNursing().getNursingId() == null) {
            Map<String, String> params = new HashMap<>();
            params.put("operationNo", PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_OPERATION_ID) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.NURSEBEAN));
            presenter.insertNurseDate(params);
        } else {
            Map<String, String> params = new HashMap<>();
            params.put("accountId", PreferenceHelper.readInt(aty, AppConfig.USER_INFO, AppConfig.USER_ACCOUNT) + "");
            params.put("fullName", PreferenceHelper.readString(aty, AppConfig.USER_INFO, AppConfig.USER_FULLNAME) + "");
            params.put("saveData", JSON.toJSONString(AppConfig.NURSEBEAN));
            presenter.updateNurseDate(params);
        }
    }

    private void initDatePicker(final TextView view) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.CHINA);
        Date date1 = null;
        try {
            if (view.getText().toString().length() > 0) {
                date1 = sdf.parse(view.getText().toString());
            } else {
                date1 = new Date();
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
        String now = sdf.format(date1);

        CustomDatePicker customDatePicker1 = new CustomDatePicker(this, new CustomDatePicker.ResultHandler() {
            @Override
            public void handle(String time) { // 回调接口，获得选中的时间
                view.setText(time);
            }
        }, "2010-01-01 00:00", now); // 初始化日期格式请用：yyyy-MM-dd HH:mm，否则不能正常运行
        customDatePicker1.showSpecificTime(true); // 显示时和分
        customDatePicker1.setIsLoop(true); // 循环滚动
        customDatePicker1.show(now);
    }

    @Override
    public void insertNurseDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void updateNurseDate(SubmitBean submitBean) {
        if (submitBean.getCode() == 200) {
            ViewInject.toast("保存成功");
            finish();
        } else {
            ViewInject.toast(submitBean.getDesc());
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }

    /**
     * 通过dispatchTouchEvent每次ACTION_DOWN事件中动态判断非EditText本身区域的点击事件，然后在事件中进行屏蔽。然后当点击不是EditText时候，进行隐藏键盘操作
     *
     * @param ev
     * @return
     */

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            View v = getCurrentFocus();
            if (isShouldHideInput(v, ev)) {

                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null) {
                    imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
                }
            }
            return super.dispatchTouchEvent(ev);
        }
        if (getWindow().superDispatchTouchEvent(ev)) {
            return true;
        }
        return onTouchEvent(ev);
    }

    public boolean isShouldHideInput(View v, MotionEvent event) {

        if (v != null && (v instanceof EditText)) {
            int[] leftTop = {0, 0};
            //获取输入框当前的location位置
            v.getLocationInWindow(leftTop);
            int left = leftTop[0];
            int top = leftTop[1];
            int bottom = top + v.getHeight();
            int right = left + v.getWidth();
            if (event.getX() > left && event.getX() < right
                    && event.getY() > top && event.getY() < bottom) {
                // 点击的是输入框区域，保留点击EditText的事件\
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case 20000:
                if (data.getExtras().getInt("position") == -1) {
                    DrugBean drug = (DrugBean) data.getExtras().getSerializable("drug");
                    OtherDrugBeans.add(drug);
                    if (otherListAdapter != null) {
                        otherListAdapter.notifyDataSetChanged();
                    } else {
                        otherListAdapter = new OtherListAdapter(analgesiaListview, OtherDrugBeans, R.layout.item_other_list);
                        analgesiaListview.setAdapter(otherListAdapter);
                    }
                } else {
                    DrugBean drug = (DrugBean) data.getExtras().getSerializable("drug");
                    OtherDrugBeans.set(data.getExtras().getInt("position"), drug);
                    if (otherListAdapter != null) {
                        otherListAdapter.notifyDataSetChanged();
                    } else {
                        otherListAdapter = new OtherListAdapter(analgesiaListview, OtherDrugBeans, R.layout.item_other_list);
                        analgesiaListview.setAdapter(otherListAdapter);
                    }
                }
                break;
            default:
                break;
        }
    }

}
